# -*- coding: utf-8 -*-
from ip.opdef import *
from mtl.base import OP_FILE


def add(dst, src0, src1, alu=None, pid=None, dst_inc=None, offset=None, ain0=None, wait0=None, offset0=None, ain1=None, wait1=None, offset1=None):
    op = ExecOp()
    op.op_code = 1
    op.dst_addr = dst
    op.src_addr_0 = src0
    op.src_addr_1 = src1
    op.alu = (0) if alu is None else (alu)
    op.peer_id = (65535) if pid is None else (pid)
    op.dst_increase = (0) if dst_inc is None else (dst_inc)
    op.dst_enable_offset = (False) if offset is None else (offset)
    op.src_wait_aluin_0 = (False) if ain0 is None else (ain0)
    op.src_wait_passin_0 = (False) if wait0 is None else (wait0)
    op.src_enable_offset_0 = (False) if offset0 is None else (offset0)
    op.src_wait_aluin_1 = (False) if ain1 is None else (ain1)
    op.src_wait_passin_1 = (False) if wait1 is None else (wait1)
    op.src_enable_offset_1 = (False) if offset1 is None else (offset1)
    op.dst_peer_id = 0
    op.dst_stride = 1
    op.dst_sb = False
    op.len_limit = 1
    op.src_stride_0 = 1
    op.src_stride_1 = 1
    op.src_limit_0 = op.src_addr_0 + 1
    op.src_limit_1 = op.src_addr_1 + 1
    OP_FILE['eops'].append(op)


def sub(dst, src0, src1, alu=None, pid=None, dst_inc=None, offset=None, ain0=None, wait0=None, offset0=None, ain1=None, wait1=None, offset1=None):
    op = ExecOp()
    op.op_code = 2
    op.dst_addr = dst
    op.src_addr_0 = src0
    op.src_addr_1 = src1
    op.alu = (0) if alu is None else (alu)
    op.peer_id = (65535) if pid is None else (pid)
    op.dst_increase = (0) if dst_inc is None else (dst_inc)
    op.dst_enable_offset = (False) if offset is None else (offset)
    op.src_wait_aluin_0 = (False) if ain0 is None else (ain0)
    op.src_wait_passin_0 = (False) if wait0 is None else (wait0)
    op.src_enable_offset_0 = (False) if offset0 is None else (offset0)
    op.src_wait_aluin_1 = (False) if ain1 is None else (ain1)
    op.src_wait_passin_1 = (False) if wait1 is None else (wait1)
    op.src_enable_offset_1 = (False) if offset1 is None else (offset1)
    op.dst_peer_id = 0
    op.dst_stride = 1
    op.dst_sb = False
    op.len_limit = 1
    op.src_stride_0 = 1
    op.src_stride_1 = 1
    op.src_limit_0 = op.src_addr_0 + 1
    op.src_limit_1 = op.src_addr_1 + 1
    OP_FILE['eops'].append(op)


def mul(dst, src0, src1, alu=None, pid=None, dst_inc=None, offset=None, ain0=None, wait0=None, offset0=None, ain1=None, wait1=None, offset1=None):
    op = ExecOp()
    op.op_code = 3
    op.dst_addr = dst
    op.src_addr_0 = src0
    op.src_addr_1 = src1
    op.alu = (0) if alu is None else (alu)
    op.peer_id = (65535) if pid is None else (pid)
    op.dst_increase = (0) if dst_inc is None else (dst_inc)
    op.dst_enable_offset = (False) if offset is None else (offset)
    op.src_wait_aluin_0 = (False) if ain0 is None else (ain0)
    op.src_wait_passin_0 = (False) if wait0 is None else (wait0)
    op.src_enable_offset_0 = (False) if offset0 is None else (offset0)
    op.src_wait_aluin_1 = (False) if ain1 is None else (ain1)
    op.src_wait_passin_1 = (False) if wait1 is None else (wait1)
    op.src_enable_offset_1 = (False) if offset1 is None else (offset1)
    op.dst_peer_id = 0
    op.dst_stride = 1
    op.dst_sb = False
    op.len_limit = 1
    op.src_stride_0 = 1
    op.src_stride_1 = 1
    op.src_limit_0 = op.src_addr_0 + 1
    op.src_limit_1 = op.src_addr_1 + 1
    OP_FILE['eops'].append(op)


def div(dst, src0, src1, alu=None, pid=None, dst_inc=None, offset=None, ain0=None, wait0=None, offset0=None, ain1=None, wait1=None, offset1=None):
    op = ExecOp()
    op.op_code = 4
    op.dst_addr = dst
    op.src_addr_0 = src0
    op.src_addr_1 = src1
    op.alu = (0) if alu is None else (alu)
    op.peer_id = (65535) if pid is None else (pid)
    op.dst_increase = (0) if dst_inc is None else (dst_inc)
    op.dst_enable_offset = (False) if offset is None else (offset)
    op.src_wait_aluin_0 = (False) if ain0 is None else (ain0)
    op.src_wait_passin_0 = (False) if wait0 is None else (wait0)
    op.src_enable_offset_0 = (False) if offset0 is None else (offset0)
    op.src_wait_aluin_1 = (False) if ain1 is None else (ain1)
    op.src_wait_passin_1 = (False) if wait1 is None else (wait1)
    op.src_enable_offset_1 = (False) if offset1 is None else (offset1)
    op.dst_peer_id = 0
    op.dst_stride = 1
    op.dst_sb = False
    op.len_limit = 1
    op.src_stride_0 = 1
    op.src_stride_1 = 1
    op.src_limit_0 = op.src_addr_0 + 1
    op.src_limit_1 = op.src_addr_1 + 1
    OP_FILE['eops'].append(op)


def add_v(dst, count, src0, src1, alu=None, pid=None, dst_inc=None, dst_stride=None, offset=None, ain0=None, wait0=None, stride0=None, offset0=None, limit0=None, ain1=None, wait1=None, stride1=None, offset1=None, limit1=None):
    op = ExecOp()
    op.op_code = 1
    op.dst_addr = dst
    op.len_limit = count
    op.src_addr_0 = src0
    op.src_addr_1 = src1
    op.alu = (0) if alu is None else (alu)
    op.peer_id = (65535) if pid is None else (pid)
    op.dst_increase = (0) if dst_inc is None else (dst_inc)
    op.dst_stride = (1) if dst_stride is None else (dst_stride)
    op.dst_enable_offset = (False) if offset is None else (offset)
    op.src_wait_aluin_0 = (False) if ain0 is None else (ain0)
    op.src_wait_passin_0 = (False) if wait0 is None else (wait0)
    op.src_stride_0 = (1) if stride0 is None else (stride0)
    op.src_enable_offset_0 = (False) if offset0 is None else (offset0)
    op.src_limit_0 = (op.src_addr_0 + op.len_limit * op.src_stride_0) if limit0 is None else (limit0)
    op.src_wait_aluin_1 = (False) if ain1 is None else (ain1)
    op.src_wait_passin_1 = (False) if wait1 is None else (wait1)
    op.src_stride_1 = (1) if stride1 is None else (stride1)
    op.src_enable_offset_1 = (False) if offset1 is None else (offset1)
    op.src_limit_1 = (op.src_addr_1 + op.len_limit * op.src_stride_1) if limit1 is None else (limit1)
    op.dst_peer_id = 0
    op.dst_sb = False
    OP_FILE['eops'].append(op)


def sub_v(dst, count, src0, src1, alu=None, pid=None, dst_inc=None, dst_stride=None, offset=None, ain0=None, wait0=None, stride0=None, offset0=None, limit0=None, ain1=None, wait1=None, stride1=None, offset1=None, limit1=None):
    op = ExecOp()
    op.op_code = 2
    op.dst_addr = dst
    op.len_limit = count
    op.src_addr_0 = src0
    op.src_addr_1 = src1
    op.alu = (0) if alu is None else (alu)
    op.peer_id = (65535) if pid is None else (pid)
    op.dst_increase = (0) if dst_inc is None else (dst_inc)
    op.dst_stride = (1) if dst_stride is None else (dst_stride)
    op.dst_enable_offset = (False) if offset is None else (offset)
    op.src_wait_aluin_0 = (False) if ain0 is None else (ain0)
    op.src_wait_passin_0 = (False) if wait0 is None else (wait0)
    op.src_stride_0 = (1) if stride0 is None else (stride0)
    op.src_enable_offset_0 = (False) if offset0 is None else (offset0)
    op.src_limit_0 = (op.src_addr_0 + op.len_limit * op.src_stride_0) if limit0 is None else (limit0)
    op.src_wait_aluin_1 = (False) if ain1 is None else (ain1)
    op.src_wait_passin_1 = (False) if wait1 is None else (wait1)
    op.src_stride_1 = (1) if stride1 is None else (stride1)
    op.src_enable_offset_1 = (False) if offset1 is None else (offset1)
    op.src_limit_1 = (op.src_addr_1 + op.len_limit * op.src_stride_1) if limit1 is None else (limit1)
    op.dst_peer_id = 0
    op.dst_sb = False
    OP_FILE['eops'].append(op)


def mul_v(dst, count, src0, src1, alu=None, pid=None, dst_inc=None, dst_stride=None, offset=None, ain0=None, wait0=None, stride0=None, offset0=None, limit0=None, ain1=None, wait1=None, stride1=None, offset1=None, limit1=None):
    op = ExecOp()
    op.op_code = 3
    op.dst_addr = dst
    op.len_limit = count
    op.src_addr_0 = src0
    op.src_addr_1 = src1
    op.alu = (0) if alu is None else (alu)
    op.peer_id = (65535) if pid is None else (pid)
    op.dst_increase = (0) if dst_inc is None else (dst_inc)
    op.dst_stride = (1) if dst_stride is None else (dst_stride)
    op.dst_enable_offset = (False) if offset is None else (offset)
    op.src_wait_aluin_0 = (False) if ain0 is None else (ain0)
    op.src_wait_passin_0 = (False) if wait0 is None else (wait0)
    op.src_stride_0 = (1) if stride0 is None else (stride0)
    op.src_enable_offset_0 = (False) if offset0 is None else (offset0)
    op.src_limit_0 = (op.src_addr_0 + op.len_limit * op.src_stride_0) if limit0 is None else (limit0)
    op.src_wait_aluin_1 = (False) if ain1 is None else (ain1)
    op.src_wait_passin_1 = (False) if wait1 is None else (wait1)
    op.src_stride_1 = (1) if stride1 is None else (stride1)
    op.src_enable_offset_1 = (False) if offset1 is None else (offset1)
    op.src_limit_1 = (op.src_addr_1 + op.len_limit * op.src_stride_1) if limit1 is None else (limit1)
    op.dst_peer_id = 0
    op.dst_sb = False
    OP_FILE['eops'].append(op)


def div_v(dst, count, src0, src1, alu=None, pid=None, dst_inc=None, dst_stride=None, offset=None, ain0=None, wait0=None, stride0=None, offset0=None, limit0=None, ain1=None, wait1=None, stride1=None, offset1=None, limit1=None):
    op = ExecOp()
    op.op_code = 4
    op.dst_addr = dst
    op.len_limit = count
    op.src_addr_0 = src0
    op.src_addr_1 = src1
    op.alu = (0) if alu is None else (alu)
    op.peer_id = (65535) if pid is None else (pid)
    op.dst_increase = (0) if dst_inc is None else (dst_inc)
    op.dst_stride = (1) if dst_stride is None else (dst_stride)
    op.dst_enable_offset = (False) if offset is None else (offset)
    op.src_wait_aluin_0 = (False) if ain0 is None else (ain0)
    op.src_wait_passin_0 = (False) if wait0 is None else (wait0)
    op.src_stride_0 = (1) if stride0 is None else (stride0)
    op.src_enable_offset_0 = (False) if offset0 is None else (offset0)
    op.src_limit_0 = (op.src_addr_0 + op.len_limit * op.src_stride_0) if limit0 is None else (limit0)
    op.src_wait_aluin_1 = (False) if ain1 is None else (ain1)
    op.src_wait_passin_1 = (False) if wait1 is None else (wait1)
    op.src_stride_1 = (1) if stride1 is None else (stride1)
    op.src_enable_offset_1 = (False) if offset1 is None else (offset1)
    op.src_limit_1 = (op.src_addr_1 + op.len_limit * op.src_stride_1) if limit1 is None else (limit1)
    op.dst_peer_id = 0
    op.dst_sb = False
    OP_FILE['eops'].append(op)


def wait(src, alu=None, pid=None, src_offset=None):
    op = ExecOp()
    op.op_code = 70
    op.src_addr_0 = src
    op.alu = (0) if alu is None else (alu)
    op.peer_id = (65535) if pid is None else (pid)
    op.src_enable_offset_0 = (False) if src_offset is None else (src_offset)
    op.len_limit = 1
    op.dst_stride = 0
    op.dst_addr = 0
    op.dst_increase = 0
    op.dst_peer_id = 0
    op.dst_enable_offset = False
    op.dst_sb = False
    op.src_stride_0 = 1
    op.src_wait_passin_0 = False
    op.src_wait_aluin_0 = False
    op.src_limit_0 = op.src_addr_0 + 1
    op.src_addr_1 = 0
    op.src_wait_passin_1 = False
    op.src_wait_aluin_1 = False
    op.src_enable_offset_1 = 0
    op.src_stride_1 = 0
    op.src_limit_1 = 0
    OP_FILE['eops'].append(op)


def wait_v(count, src, alu=None, pid=None, src_stride=None, src_offset=None):
    op = ExecOp()
    op.op_code = 70
    op.len_limit = count
    op.src_addr_0 = src
    op.alu = (0) if alu is None else (alu)
    op.peer_id = (65535) if pid is None else (pid)
    op.src_stride_0 = (1) if src_stride is None else (src_stride)
    op.src_enable_offset_0 = (False) if src_offset is None else (src_offset)
    op.dst_stride = 0
    op.dst_addr = 0
    op.dst_increase = 0
    op.dst_peer_id = 0
    op.dst_enable_offset = False
    op.dst_sb = False
    op.src_wait_passin_0 = False
    op.src_wait_aluin_0 = False
    op.src_limit_0 = op.src_addr_0 + 1
    op.src_addr_1 = 0
    op.src_wait_passin_1 = False
    op.src_wait_aluin_1 = False
    op.src_enable_offset_1 = 0
    op.src_stride_1 = 0
    op.src_limit_1 = 0
    OP_FILE['eops'].append(op)


def put(dst_pid, dst, src_pid, src, dst_sb=None, dst_inc=None, src_alu=None, src_wait=None, src_ain=None, src_offset=None):
    op = ExecOp()
    op.op_code = 20
    op.dst_peer_id = dst_pid
    op.dst_addr = dst
    op.peer_id = src_pid
    op.src_addr_0 = src
    op.dst_sb = (False) if dst_sb is None else (dst_sb)
    op.dst_increase = (0) if dst_inc is None else (dst_inc)
    op.alu = (0) if src_alu is None else (src_alu)
    op.src_wait_passin_0 = (False) if src_wait is None else (src_wait)
    op.src_wait_aluin_0 = (False) if src_ain is None else (src_ain)
    op.src_enable_offset_0 = (False) if src_offset is None else (src_offset)
    op.len_limit = 1
    op.dst_enable_offset = False
    op.dst_stride = 1
    op.src_stride_0 = 1
    op.src_limit_0 = op.src_addr_0 + 1
    op.src_addr_1 = op.src_addr_0
    op.src_wait_passin_1 = False
    op.src_wait_aluin_1 = False
    op.src_enable_offset_1 = op.src_enable_offset_0
    op.src_stride_1 = 1
    op.src_limit_1 = op.src_addr_0 + 1
    OP_FILE['eops'].append(op)


def put_v(dst_pid, dst, count, src_pid, src, dst_inc=None, dst_stride=None, dst_sb=None, src_alu=None, src_wait=None, src_ain=None, src_stride=None, src_offset=None, src_limit=None):
    op = ExecOp()
    op.op_code = 20
    op.dst_peer_id = dst_pid
    op.dst_addr = dst
    op.len_limit = count
    op.peer_id = src_pid
    op.src_addr_0 = src
    op.dst_increase = (0) if dst_inc is None else (dst_inc)
    op.dst_stride = (1) if dst_stride is None else (dst_stride)
    op.dst_sb = (False) if dst_sb is None else (dst_sb)
    op.alu = (0) if src_alu is None else (src_alu)
    op.src_wait_passin_0 = (False) if src_wait is None else (src_wait)
    op.src_wait_aluin_0 = (False) if src_ain is None else (src_ain)
    op.src_stride_0 = (1) if src_stride is None else (src_stride)
    op.src_enable_offset_0 = (False) if src_offset is None else (src_offset)
    op.src_limit_0 = (op.src_addr_0 + op.len_limit) if src_limit is None else (src_limit)
    op.dst_enable_offset = False
    op.src_addr_1 = op.src_addr_0
    op.src_wait_passin_1 = False
    op.src_wait_aluin_1 = False
    op.src_enable_offset_1 = op.src_enable_offset_0
    op.src_stride_1 = 1
    op.src_limit_1 = op.src_addr_0 + 1
    OP_FILE['eops'].append(op)


def halt():
    op = ExecOp()
    op.op_code = 100
    op.alu = 15
    op.peer_id = 65535
    op.dst_sb = False
    op.len_limit = 0
    op.dst_addr = 0
    op.dst_increase = 0
    op.dst_enable_offset = False
    op.dst_peer_id = 0
    op.dst_stride = 0
    op.src_addr_0 = 0
    op.src_wait_passin_0 = False
    op.src_wait_aluin_0 = False
    op.src_enable_offset_0 = False
    op.src_stride_0 = 0
    op.src_limit_0 = 0
    op.src_addr_1 = 0
    op.src_wait_passin_1 = False
    op.src_wait_aluin_1 = False
    op.src_enable_offset_1 = False
    op.src_stride_1 = 0
    op.src_limit_1 = 0
    OP_FILE['eops'].append(op)

